package com.公司笔试草稿;

import java.util.*;


public class work01 {

}


class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     * @param data string字符串 输入的待校验的字符串
     * @return bool布尔型
     */
    public boolean solution(String data) {
        // write code here
        if (data.length() < 1) {
            return true;
        }


        Deque<Character> stack = new LinkedList<>();

        for (int i = 0; i < data.length(); i++) {
            char s = data.charAt(i);

            if (s == '[') {
                stack.push(s);
            } else if (s == ']') {
                if(stack.isEmpty()){
                    return false;
                }

                char t = stack.removeLast();
                if ( t == ']') {
                    return false;
                }
                // 成功配对什么也不干

            } else if (s == '.') {
                if (stack.isEmpty()) {
                    stack.push(s);
                }else {
                    // 配对前一项 取出来
                    stack.poll();
                }

            }
        }

        // 最后取出空字符
        while (!stack.isEmpty()){
            if (stack.removeLast() != '.'){
                return false;
            }
        }
        return stack.isEmpty();
    }

    public static void main(String[] args) {
        String test = "[]";
        Solution work = new Solution();
        boolean res = work.solution(test);
        System.out.println(res);

    }
}